package com.acwing.partition36;

import java.io.*;

/**
 * @author rkc
 * @date 2022/7/23 10:42
 */
public class AC3559围圈报数 {

    private static final int N = 55;
    private static int[] ne = new int[N];
    private static int n;

    private static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    private static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        int k = nextInt();
        while (k-- > 0) {
            n = nextInt();
            for (int i = 1; i <= n; i++) ne[i] = i + 1;
            ne[n] = 1;
            int u = 1, last = -1, step = 1;
            while (u != ne[u]) {
                if (step % 3 == 0) {
                    //删除u
                    writer.print(u + " ");
                    ne[last] = ne[u];
                    u = ne[last];
                } else {
                    last = u;
                    u = ne[u];
                }
                step++;
            }
            writer.println(u);
        }
        writer.flush();
    }

    private static int nextInt() throws IOException {
        tokenizer.nextToken();
        return (int) tokenizer.nval;
    }
}
